/*
Java source file
Copyright: Umschalt.com 2012
*/
package com.david.documentation.domain.dao.link;

import com.david.documentation.domain.dao.AbstractDAO;
import com.david.documentation.domain.entities.link.Link;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Repository(value = "linkDao")
public class LinkDaoImpl extends AbstractDAO<Link> implements LinkDao {

	@PersistenceContext
    private EntityManager entityManager;

	public EntityManager getEntityManager() {
		return entityManager;
	}

	public Class<Link> getClazz() {
		return Link.class;
	}

	@Transactional
	public boolean checkforDublicate(String link) {
		Query query = getEntityManager().createQuery("from " + getClazz().getSimpleName() + " e where e.link = :aLink");
        query.setParameter("aLink", link);
        return query.getResultList().size() > 0;
	}
}
